package lovoStudy_9_13.Puck;

import java.util.*;

/**
 * Created with Intellij IDEA
 * Description:
 *
 * @ return:
 * @ author:zxl
 */
public class DouDiZhu {
    //List subList
    ArrayList<Puck> arrayList = new ArrayList<>();

    public void process(){
        init();
        shuffle();
        sendCard();
    }

    /**
     * 初始化54张扑克牌
     */
    public void init(){
// 3 4 5 6 7 8 9 10 j Q K A 2 x X
        wo(arrayList,"方片");
        wo(arrayList,"梅花");
        wo(arrayList,"红心");
        wo(arrayList,"黑桃");
        arrayList.add(new Puck("小王","JOKER",16));
        arrayList.add(new Puck("大王","JOKER",17));
    }

    /**
     * 产生扑克对象方法
     * */
    public void wo(ArrayList arrayList,String type){
        for (int i = 2 ; i <= 14 ; i++){
            if (i == 2){
                arrayList.add(new Puck( i  + "",type,15));
                continue;
            }
            if (i == 11){
                arrayList.add(new Puck( "j",type,11));
                continue;
            }
            if (i == 12){
                arrayList.add(new Puck( "Q",type,12));
                continue;
            }
            if (i == 13){
                arrayList.add(new Puck( "K",type,13));
                continue;
            }
            if (i == 14){
                arrayList.add(new Puck( "A",type,14));
                continue;
            }
            arrayList.add(new Puck( i  + " ",type,i));
        }
    }
    /**
     * 洗牌
     */
    public void shuffle(){
        Collections.shuffle(arrayList);
    }

    /**
     * 发牌
     */
    public void sendCard(){
        List<Puck> player1 = wow(0,17);
        List<Puck> player2 = wow(17,34);
        List<Puck> player3 = wow(34,51);


                for (Puck puck : player1 ){
            System.out.println(puck.getPoint() + " " + puck.getType());
        }
        System.out.println();
        for (Puck puck : player2 ){
            System.out.println(puck.getPoint() + " " + puck.getType());
        }
        System.out.println();
        for (Puck puck : player3 ){
            System.out.println(puck.getPoint() + " " + puck.getType());
        }
    }

    public List<Puck> wow(int a, int b){
        List<Puck> newArrayList =  arrayList.subList(a,b);
        Collections.sort(newArrayList, new Comparator<Puck>() {
            @Override
            public int compare(Puck o1, Puck o2) {
                return o1.getNum() - o2.getNum();
            }
        });
        return newArrayList;

    }




}
